<?php

/**
 * Subclass for representing a row from the 'rechner' table.
 *
 * 
 *
 * @package lib.model
 */ 
class Rechner extends BaseRechner
{

  public function getCategoryNameById($cid)
  {
	$category = KategoriePeer::retrieveByPk($cid);
		
    return $category->getName();
 
  }

  public function getCategories()
  {
	$c = new Criteria();
	$c->addAscendingOrderByColumn(KategoriePeer::NAME);
  	
	$categories = KategoriePeer::doSelect($c);
		
    return $categories;
 
  }

  public function getAllHWUser()
  {
	$c = new Criteria();
  	$hwuser = ArbeitsplatznutzerPeer::doSelect($c);
		
    return $hwuser;
  }  

  public function getHWUserId()
  {
	$c = new Criteria();
	$c->add(ArbeitsplatznutzerHasRechnerPeer::RECHNER_ID, self::getId());  		
  	
	$hwuser = ArbeitsplatznutzerHasRechnerPeer::doSelect($c);
	
	#print_r($hwuser); die;
		
    return !empty($hwuser) > 0 ? $hwuser[0]->getArbeitsplatznutzerId() : null;
  }   
  
  public function getSoftware()
  {
	$c = new Criteria();
	$c->addAscendingOrderByColumn(SoftwarePeer::KATEGORIE_ID);
	$c->addJoin(RechnerHasSoftwarePeer::SOFTWARE_ID, SoftwarePeer::ID);
	$c->add(RechnerHasSoftwarePeer::RECHNER_ID, self::getId());  		
  	
	$software = SoftwarePeer::doSelect($c);
		
    return $software;
 
  }

  public function getInstalledSoftwareById($hId,$sId){
  	
  	$c = new Criteria();
	$c->add(RechnerHasSoftwarePeer::RECHNER_ID, $hId); 		
  	$c->add(RechnerHasSoftwarePeer::SOFTWARE_ID, $sId);
	
	$software = RechnerHasSoftwarePeer::doSelect($c);

	return !empty($software) > 0 ? $software[0] : null;
  }
  
  public function getSoftwareByCategoryId($catId, $hId)
  {	
  	$installed_software = self::getSoftware();
  	
  	$c = new Criteria();
	$c->addAscendingOrderByColumn(SoftwarePeer::NAME);
	$c->addAscendingOrderByColumn(SoftwarePeer::VERSION);	
	$c->add(SoftwarePeer::KATEGORIE_ID, $catId); 		
  	
	$software = SoftwarePeer::doSelect($c);
	
	$viewed_software = array();
	$arr_of_installed_software_item = array();
	foreach($software as $software_item){
		$installed_software_item = self::getInstalledSoftwareById($hId,$software_item->getId());
		
		if($installed_software_item == null){
			array_push($viewed_software, $software_item);
		}
	}
	
    return $viewed_software;
 
  }  
  
  public function getAllSoftware()
  {
	$c = new Criteria();
	$c->addJoin(SoftwarePeer::KATEGORIE_ID, KategoriePeer::ID);
  	
	$software = SoftwarePeer::doSelect($c);
    return $software;
 
  }  
 
}
